The File Watcher SDK consists of a demo app and all necessary interface and header files to incorporate File Watcher support into your own apps. The sample code is a CodeWarrior Pro 4 project that demonstrates the use of the interface mechanisms. The user interface for this demo app is handled via PowerPlant. If PowerPlant isn't your bag, it should be fairly easy to extract the user interface code from the rest of the app.
The callback signature looks like this:
pascal void MyFileWatcherCallback( FileWatcherCallbackRec *cb, FileWatcherRecord *data );
Here is a relevant code fragment illustrating how to register a callback with the FBA:
// The record to be passed to the FBA. FileWatcherCallbackRec gMyFWCallback; // This macro is defined in FileWatcherInterface.h. DeclareFileWatcherCallbackProc( gFileWatcherCallback, MyFileWatcherCallback ); UInt32 theMask = 0x0000; theMask |= kCreatedFile; /* Valid mask values (defined in FileWatcherInterface.h) are: kCreatedFile 0x01 kCreatedFolder 0x02 kRenamedItem 0x04 kDeletedItem 0x08 kMovedItem 0x10 kEveryAction kCreatedFile + kCreatedFolder + kRenamedItem + kDeletedItem + kMovedItem This next value allows the FBA to intervene, and call the callback during normal event processing: kCallAtSystemTaskTime 0x80000000 It can be ORed with the other mask values. If you don't use it, the extension will call the callback directly when an action occurs. */ SelectorFunctionUPP interface; // Ask the FBA for its UPP. // Further calls will go through the UPP. OSErr theErr = GetFileWatcherExtensionInterface( &interface ); if ( theErr == noErr ) { // Check the version number if appropriate. NumVersionVariant version; theErr = GetFileWatcherExtensionVersion( interface, &version ); // We will ask the FBA to insert our callback record into the queue. // Get the first queue element. QHdrPtr callbackQueue; theErr = GetFileWatcherExtensionCallbackQueue( interface, &callbackQueue ); // Set the record values. gMyFWCallback.actionMask = theMask; gMyFWCallback.proc = gFileWatcherCallback; // Ask the FBA to insert our record into the queue. theErr = InstallFileWatcherExtensionCallback( callbackQueue, &gMyFWCallback ); ... }
theErr = RemoveFileWatcherExtensionCallback( callbackQueue, &gMyFWCallback );